/**
 * 扑克基础类
 */
var BaseNode = require('./../../FrameWork/Component/BaseNode');
module.exports = cc.Class({
    extends: BaseNode,
    properties: {
        iconCard: {
            default: null,
            type: cc.Sprite,
            displayName: '扑克牌'
        },
        iconTypeSmall: {
            default: null,
            type: cc.Sprite,
            displayName: '小花色'
        },
        iconTypeBig: {
            default: null,
            type: cc.Sprite,
            displayName: '大花色'
        },
        spriteAtlasCard: {
            default: null,
            type: cc.SpriteAtlas,
            displayName: '卡牌资源集合'
        },
    },

    /**
     * 
     * @param {卡牌基础信息} cardInfo:{
     *  id:1,
     *  cardType:1,
     *  value:1,
     *  iconName,"1D",
     *  chinaName:方块A 
     * }
     */
    refreshUI(cardInfo) {
        // this.iconCard.sprintFrmae = 
        if (null == cardInfo) {
            cc.error('牌的信息异常');
            return;
        }
        this.cardInfo = cardInfo;
        if (null == cardInfo.iconName) {
            cc.error('iconName：牌的信息异常');
            return;
        }

        var cardType = cardInfo.cardType;
        var value = cardInfo.value;

        if (cardType <= 4) {
            //牌值
            var colorName = (4 == cardType || 2 == cardType) ? 'b_' : 'r_';
            var cardValueSpName = colorName + value.toString();
            var spriteFrame = this.spriteAtlasCard.getSpriteFrame(cardValueSpName);
            this.iconCard.spriteFrame = spriteFrame;

            //花色
            var colorSpName = 'color_' + cardType.toString();
            var spriteFrameType = this.spriteAtlasCard.getSpriteFrame(colorSpName);
            this.iconTypeSmall.spriteFrame = spriteFrameType;
            if (value <= 10 || value == 14 || value == 16) {
                this.iconTypeBig.spriteFrame = spriteFrameType;
                this.iconTypeBig.node.y = -80;
            } else {
                var cardHeadIco = this.spriteAtlasCard.getSpriteFrame('ico_' + value.toString());
                this.iconTypeBig.spriteFrame = cardHeadIco;
                this.iconTypeBig.node.setContentSize(cardHeadIco._originalSize);
            }
        } else {
            //处理王牌
            var spriteFrame = this.spriteAtlasCard.getSpriteFrame('joker_' + value.toString());
            this.iconCard.spriteFrame = spriteFrame;
            this.iconTypeSmall.node.active = false;

            var cardHeadIco = this.spriteAtlasCard.getSpriteFrame('color_joker_' + value.toString());
            this.iconTypeBig.spriteFrame = cardHeadIco;
            this.iconTypeBig.node.setContentSize(cardHeadIco._originalSize);
        }
    },

    /***通过卡牌ID刷新牌UI信息 */
    refreshUIByCardId(cardId) {
        var cardInfo = this.setCardId(cardId);
        this.refreshUI(cardInfo);
    },

    setCardId(cardId) {
        this.cardInfo = PlanApi.PlanPkConfig.findById(cardId);
        return this.cardInfo;
    },

    getCardValue() {
        return this.cardInfo.value;
    },
    getCardInfo() {
        return this.cardInfo;
    },
    getCardId() {
        return this.cardInfo.id;
    },
    /***实际要显示的坐标 */
    getPositionActual() {
        return this.posActual;
    },

    /***实际要显示的坐标 */
    setPositionActual(pos) {
        this.posActual = pos;
    }
});